<?php
require_once (HOME.'include/base/FrontendController.php');

/**
 * 采用swfupload 进行上传
 * 对于图片上传 额外进行处理
 * @author silenus
 *
 */
class filesupload extends FrontendController {
	private $uploader;
	var $_file              = null;
	var $_allowed_file_type = null;
	var $_allowed_file_size = null;
	var $_root_dir          = null;
	
	
	
	
	/**
	 *    设定允许添加的文件类型
	 *	  @author silenus
	 *    @param     string $type 示例：gif|jpg|jpeg|png
	 *    @return    void
	 */
	function  allowed_type($type)
	{
		$type = strtolower($type);
		$this->_allowed_file_type = explode('|', $type);
	}
	
	/**
	 * 取得文件类型
	 * @param string $filename
	 * @return string 文件类型
	 */
	protected function _get_mimetype($filename)
	{
		preg_match("|\.([a-z0-9]{2,4})$|i", $filename, $fileSuffix);
		switch(strtolower($fileSuffix[1]))
		{
			case "js" :
				return "application/x-javascript";
	
			case "json" :
				return "application/json";
	
			case "jpg" :
			case "jpeg" :
			case "jpe" :
				return "image/jpeg";
	
			case "png" :
			case "gif" :
			case "bmp" :
			case "tiff" :
				return "image/".strtolower($fileSuffix[1]);
	
			case "css" :
				return "text/css";
	
			case "xml" :
				return "application/xml";
	
			case "doc" :
			case "docx" :
				return "application/msword";
	
			case "xls" :
			case "xlt" :
			case "xlm" :
			case "xld" :
			case "xla" :
			case "xlc" :
			case "xlw" :
			case "xll" :
				return "application/vnd.ms-excel";
	
			case "ppt" :
			case "pps" :
				return "application/vnd.ms-powerpoint";
	
			case "rtf" :
				return "application/rtf";
	
			case "pdf" :
				return "application/pdf";
	
			case "html" :
			case "htm" :
			case "php" :
				return "text/html";
	
			case "txt" :
				return "text/plain";
	
			case "mpeg" :
			case "mpg" :
			case "mpe" :
				return "video/mpeg";
	
			case "mp3" :
				return "audio/mpeg3";
	
			case "wav" :
				return "audio/wav";
	
			case "aiff" :
			case "aif" :
				return "audio/aiff";
	
			case "avi" :
				return "video/msvideo";
	
			case "wmv" :
				return "video/x-ms-wmv";
	
			case "mov" :
				return "video/quicktime";
				
			case "flv" :
				return 'video/x-flv';

			case "rar" :
				return "application/x-rar-compressed";
	
			case "zip" :
				return "application/zip";
	
			case "tar" :
				return "application/x-tar";
	
			case "swf" :
				return "application/x-shockwave-flash";
	
			default :
				if(function_exists("mime_content_type"))
				{
					$fileSuffix = mime_content_type($filename);
					return $fileSuffix;
				}
				return 'application/octet-stream';
		}
	}
}
